home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 101-125 / scopedisk122 / popup / source / select.c < prev    next >
C/C++ Source or Header  |  1995-03-19  |  5KB  |  187 lines

  1. #include "PopUpMenu.h"
  2.  
  3. /***************************************
  4.  * SelectItem() - check mouseposition. *
  5.  *                       *
  6.  * Input:                   *
  7.  *   none                   *
  8.  * Output:                   *
  9.  *   none                   *
  10.  ***************************************/
  11. VOID SelectItem()
  12. {
  13.   IMPORT struct WindowData MenuWindow, ItemWindow, SubWindow;
  14.   IMPORT struct MenuItem *CurrentSubItem, *CurrentItem, *TempItem;
  15.   IMPORT struct Menu *CurrentMenuPtr;
  16.   IMPORT UWORD    CurrentMenuNr;
  17.   IMPORT const UWORD  MenuFontSize;
  18.   IMPORT const WORD   MouseY;
  19.   IMPORT struct RastPort Rp;
  20.  
  21.   /********************
  22.    * Check subwindow. *
  23.    ********************/
  24.  
  25.   if (SubWindow.BitMapOk) {
  26.     struct MenuItem *const NewSubItem = FindMouseItem(&SubWindow);
  27.  
  28.     if (NewSubItem != CurrentSubItem) {
  29.       if (CurrentSubItem)
  30.     HighLightItem(CurrentSubItem,&SubWindow,HIGHLIGHTOFF);
  31.       else
  32.     if (TempItem) {
  33.       CurrentItem = TempItem;
  34.       TempItem = NULL;
  35.       HighLightCurrItemBehind(HIGHLIGHTON);
  36.     }
  37.       if ((CurrentSubItem = NewSubItem) != NULL)
  38.     HighLightItem(NewSubItem,&SubWindow,HIGHLIGHTON);
  39.       else {
  40.     HighLightCurrItemBehind(HIGHLIGHTOFF);
  41.     TempItem = CurrentItem;
  42.     CurrentItem = NULL;
  43.       }
  44.     }
  45.     if (MouseInWindow(&SubWindow))
  46.       return;
  47.   }
  48.  
  49.   /*********************
  50.    * Check itemwindow. *
  51.    *********************/
  52.  
  53.   if (ItemWindow.BitMapOk) {
  54.     if (MouseInWindow(&ItemWindow)) {
  55.       struct MenuItem *const NewItem = FindMouseItem(&ItemWindow);
  56.  
  57.       if (NewItem != CurrentItem) {
  58.     if (SubWindow.BitMapOk) {
  59.       CloseItemWindow(&SubWindow);
  60.       TempItem = NULL;
  61.     }
  62.     if (CurrentItem)
  63.       HighLightItem(CurrentItem,&ItemWindow,HIGHLIGHTOFF);
  64.     if ((CurrentItem = NewItem) != NULL) {
  65.       HighLightItem(NewItem,&ItemWindow,HIGHLIGHTON);
  66.       if ((NewItem->Flags & ITEMENABLED) AND
  67.          ((SubWindow.Items = NewItem->SubItem) != NULL))
  68.         OpenItemWindow(&SubWindow,&ItemWindow,
  69.                (WORD)(CurrentItem->TopEdge - ItemWindow.TopValue),
  70.                  SUBWINDOW);
  71.     }
  72.       }
  73.       return;
  74.     }
  75.     else /* mouse not in itemwindow */
  76.       if (CurrentItem) {
  77.     if (SubWindow.BitMapOk) {
  78.       HighLightCurrItemBehind(HIGHLIGHTOFF);
  79.       TempItem = CurrentItem;
  80.     }
  81.     else
  82.       HighLightItem(CurrentItem,&ItemWindow,HIGHLIGHTOFF);
  83.     CurrentItem = NULL;
  84.       }
  85.   }
  86.  
  87.   /*********************
  88.    * Check menuwindow. *
  89.    *********************/
  90.  
  91.   if (MouseInWindow(&MenuWindow)) {
  92.     const UWORD NewMenuNr = (MouseY - MenuWindow.TopEdge - BORDERSIZE)/MenuFontSize + 1;
  93.  
  94.     if (NewMenuNr != CurrentMenuNr) {
  95.       if (CurrentMenuNr) {
  96.     if (ItemWindow.BitMapOk) {
  97.       CloseItemWindow(&SubWindow);
  98.       CloseItemWindow(&ItemWindow);
  99.       TempItem = NULL;
  100.     }
  101.     ToggleMenu(CurrentMenuNr,CurrentMenuPtr); /* HIGHLIGHTOFF */
  102.       }
  103.       if ((CurrentMenuPtr = FindMenuPtr(NewMenuNr)) == NULL)
  104.     CurrentMenuNr = 0;
  105.       else {
  106.     ToggleMenu(CurrentMenuNr = NewMenuNr,CurrentMenuPtr); /* HIGHLIGHTON */
  107.     if ((CurrentMenuPtr->Flags & MENUENABLED) AND
  108.         ((ItemWindow.Items = CurrentMenuPtr->FirstItem) != NULL))
  109.       OpenItemWindow(&ItemWindow,&MenuWindow,
  110.              (WORD)((CurrentMenuNr - 1) * MenuFontSize + MenuWindow.TopEdge),
  111.              ITEMWINDOW);
  112.       }
  113.     }
  114.   }
  115.   return;
  116. }
  117.  
  118. /***************************************************
  119.  * MouseInWindow(Window) - Is mouse inside window. *
  120.  *                           *
  121.  * Input:                       *
  122.  *   Window    - Window to check.           *
  123.  * Output:                       *
  124.  *   return    - TRUE if mouse inside.           *
  125.  ***************************************************/
  126. BOOL MouseInWindow(Window)
  127.   const struct WindowData *const Window;
  128. {
  129.   IMPORT const WORD  MouseX, MouseY;
  130.  
  131.   return ((MouseX > Window->LeftEdge) AND
  132.       (MouseX < Window->RightEdge) AND
  133.       (MouseY > Window->TopEdge) AND
  134.       (MouseY < Window->Bottom));
  135. }
  136.  
  137. /****************************************************************
  138.  * FindMouseItem(ItemWindow) - Check if mouse inside an item.   *
  139.  *                                *
  140.  * Input:                            *
  141.  *   ItemWindow - Window with items                *
  142.  * Output:                            *
  143.  *   return - Pointer to item under the mousepointer (or NULL). *
  144.  ****************************************************************/
  145. struct MenuItem *FindMouseItem(ItemWindow)
  146.   const struct WindowData *const ItemWindow;
  147. {
  148.   IMPORT const WORD  MouseX,MouseY;
  149.  
  150.   const WORD MouseWinX = MouseX + ItemWindow->LeftValue;
  151.   const WORD MouseWinY = MouseY + ItemWindow->TopValue;
  152.  
  153.   struct MenuItem *Item = ItemWindow->Items;
  154.  
  155.   do
  156.     if ((MouseWinY >= Item->TopEdge) AND
  157.     (MouseWinY <= Item->TopEdge + Item->Height) AND
  158.     (MouseWinX >= Item->LeftEdge) AND
  159.     (MouseWinX <= Item->LeftEdge + Item->Width))
  160.       return (Item);
  161.   while ((Item = Item->NextItem) != NULL);
  162.   return (NULL);
  163. }
  164.  
  165. /*********************************************************
  166.  * HighLightCurrItemBehind(Mode) - Highlight currentitem *
  167.  *                   behind subwindow.     *
  168.  * Input:                         *
  169.  *   Mode  - HIGHLIGHTON or HIGHLIGHTOFF.         *
  170.  * Output:                         *
  171.  *   none                         *
  172.  *********************************************************/
  173. VOID HighLightCurrItemBehind(Mode)
  174.   UWORD const Mode;
  175. {
  176.   IMPORT struct WindowData ItemWindow,SubWindow;
  177.   IMPORT struct RastPort Rp;
  178.   IMPORT struct MenuItem *const CurrentItem;
  179.  
  180.   SwapBits(&SubWindow);
  181.     HighLightItem(CurrentItem,&ItemWindow,Mode);
  182.   SwapBits(&SubWindow);
  183. }
  184.  
  185.  
  186.  
  187.